﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace text.Tree
{
    //404. 左叶子之和
    //计算给定二叉树的所有左叶子之和。
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     public int val;
     *     public TreeNode left;
     *     public TreeNode right;
     *     public TreeNode(int x) { val = x; }
     * }
     */
    public class _404
    {
        public int SumOfLeftLeaves(TreeNode root)
        {
            if (root == null) return 0;
            int res = 0;
            if (root.left != null && root.left.left == null && root.left.right == null)
            {
                res = root.left.val;
            }
            return res + SumOfLeftLeaves(root.left) + SumOfLeftLeaves(root.right) ;
        }
    }
}
